package com.tanhua.manager.controller;

import com.tanhua.manager.service.ManageService;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Map;

@RestController
@RequestMapping("/manage")
public class ManageController {

    @Autowired
    private ManageService manageService;

    @GetMapping(value = "/users", name = "分页查询用户")
    public ResponseEntity queryUsers(@RequestParam(defaultValue = "1") Integer page,
                                     @RequestParam(defaultValue = "10") Integer pagesize,
                                     Long id,
                                     String nickname,
                                     String city
    ) {

        return manageService.queryUsers(page, pagesize, id, nickname, city);
    }

    @GetMapping(value = "/users/{userID}", name = "查询用户详细信息")
    public ResponseEntity queryUsersById(@PathVariable("userID") Long userId) {

        return manageService.queryUsersById(userId);
    }

    @GetMapping(value = "/videos", name = "查询指定用户的小视频列表数据")
    public ResponseEntity queryVideos(@RequestParam(defaultValue = "1") Integer page,
                                      @RequestParam(defaultValue = "10") Integer pagesize,
                                      Long uid) {

        return manageService.queryVideos(page, pagesize, uid);
    }

    @GetMapping(value = "/messages", name = "查询指定用户的动态（圈子）列表数据")
    public ResponseEntity queryMessages(@RequestParam(defaultValue = "1") Integer page,
                                        @RequestParam(defaultValue = "10") Integer pagesize,
                                        Long uid, Integer state) {

        return manageService.queryMessages(page, pagesize, uid, state);
    }

    @GetMapping(value = "/messages/{id}", name = "查询指定动态（圈子）详情数据")
    public ResponseEntity queryMessagesDetail(@PathVariable("id") String movementId) {

        return manageService.queryMessagesDetail(movementId);
    }

    @GetMapping(value = "/messages/comments", name = "查询指定动态（圈子）的评论数据")
    public ResponseEntity queryComments(@RequestParam(defaultValue = "1") Integer page,
                                        @RequestParam(defaultValue = "10") Integer pagesize,
                                        String messageID) {

        return manageService.queryComments(page, pagesize, messageID);
    }


    //动态复审通过
    @PostMapping(value = "/messages/pass", name = "待审核通过")
    public ResponseEntity messagePass(@RequestBody String[] ids) {
        for (String id1 : ids) {
            System.out.println(id1);
            manageService.queryMovementByIdPass(id1);
        }
        return ResponseEntity.ok("成功");
    }

    //动态复审拒绝
    @PostMapping(value = "/messages/reject", name = "待审核拒绝")
    public ResponseEntity messageReject(@RequestBody String[] ids) {
        for (String id1 : ids) {
            System.out.println(id1);
            manageService.queryMovementByIdReject(id1);
        }
        return ResponseEntity.ok("拒绝");
    }
}
